package com.industrial.white.controller;

import com.industrial.common.core.web.controller.BaseController;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.common.core.web.page.TableDataInfo;
import com.industrial.common.security.annotation.RequiresPermissions;
import com.industrial.common.security.utils.SecurityUtils;
import com.industrial.white.domain.WhiteNotice;
import com.industrial.white.service.IWhiteNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.industrial.common.security.utils.SecurityUtils.getUsername;

@RestController
@RequestMapping("/notice")
public class WhiteNoticeController extends BaseController {

    @Autowired
    private IWhiteNoticeService noticeService;

    /**
     * 获取通知公告列表
     */
//    @RequiresPermissions("white:notice:list")
    @GetMapping("/list")

    public TableDataInfo list(WhiteNotice notice)
    {
        startPage();
        List<WhiteNotice> list = noticeService.selectNoticeList(notice);
        return getDataTable(list);
    }

    /**
     * 根据通知公告编号获取详细信息
     */
    @GetMapping(value = "/{noticeId}")
    public AjaxResult getInfo(@PathVariable String noticeId)
    {
        return success(noticeService.selectNoticeById(noticeId));
    }

    /**
     * 新增通知公告
     */
    @RequiresPermissions("white:notice:add")
    @PostMapping
    public AjaxResult add(@Validated @RequestBody WhiteNotice notice)
    {
        notice.setCreateBy(SecurityUtils.getUserId());
        return toAjax(noticeService.insertNotice(notice));
    }

    /**
     * 修改通知公告
     */
    @RequiresPermissions("white:notice:edit")
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody WhiteNotice notice)
    {
        notice.setUpdateBy(SecurityUtils.getUserId());
        return toAjax(noticeService.updateNotice(notice));
    }

    /**
     * 删除通知公告
     */
    @RequiresPermissions("white:notice:remove")
    @DeleteMapping("/{noticeIds}")
    public AjaxResult remove(@PathVariable String noticeIds)
    {
        return toAjax(noticeService.deleteNoticeByIds(noticeIds));
    }
}
